import re

pattern1 = re.compile(r'\(.+\)')		#括号

tPairs = []

with open('clean.txt', 'w') as tFileOut:
	with open('word.txt', 'r') as tFileIn:

		tFileInLines = tFileIn.readlines()

		for tFileInLine in tFileInLines:
			tRightSplit = tFileInLine.split("]")	#右中括号
			if( len(tRightSplit) != 2 ):
				continue

			tLeftSplit = tRightSplit[0].split("[")	#左中括号
			if( len(tLeftSplit) != 2 ):
				print("错误")
				break

			tWord = tLeftSplit[0]
			for tMatch in (pattern1.findall(tWord)):	#小括号
				tWord = tWord.replace(tMatch, "")
			tWord = tWord.replace(" ", "")				#去空格
			tWord = tWord.replace(" ", "")				#去空格


			tPhoneme = tLeftSplit[1].replace("'", "ˈ")

			tPhonemeSemicolon = tPhoneme.split(";")			#分号
			tPhoneme = tPhonemeSemicolon[0]
			tPhonemeComma = tPhoneme.split(", ")			#逗号
			tPhoneme = tPhonemeComma[0]
			tPhoneme = tPhoneme.replace(" ", "")			#空格

			for tMatch in (pattern1.findall(tPhoneme)):		#小括号
				tPhoneme = tPhoneme.replace(tMatch, "")

			tModify = ""
			tLenPhone = len(tPhoneme)
			for i in range(tLenPhone):
				tNowLet = tPhoneme[i]
				if(tNowLet=="("):
					print("有左小括号，退出")
					exit()
				elif(tNowLet==")"):
					print("有右小括号，退出")
					exit()
				elif(tNowLet=="["):
					print("有左中括号，退出")
					exit()
				elif(tNowLet=="]"):
					print("有右中括号，退出")
					exit()
				elif(tNowLet==","):
					print("有逗号，退出")
					exit()
				elif(tNowLet==" "):
					print("有空格，退出")
					exit()
				elif(tNowLet=="ɔ"):
					if(i+1<tLenPhone  and  tPhoneme[i+1]!="ː"  and  tPhoneme[i+1]!="ɪ"):
						tNowLet = "ɒ"


				tModify += tNowLet

			tPairs.append([tWord.replace(" ", ""), "["+tPhoneme+"]", tModify])

			tFileOut.write(tWord + "\t" + "["+tModify+"]" + "\n")
			

for tPair in tPairs:
	print(tPair[0], tPair[1], tPair[2])
